package com.zs4sdk.entity;

import com.common.library.entity.JSONResultEntity;
import com.common.library.util.Helper;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by cxb on 2015/5/6.
 * 分享有礼实体
 */
public class ShareEntity extends JSONResultEntity {

    private String icon;
    private String title;
    private String description;
    private String url;
    private String rule;

    // 字段 名
    public static final String COLUMN_ICON = "icon";
    public static final String COLUMN_TITLE = "title";
    public static final String COLUMN_DESCRIPTION = "description";
    public static final String COLUMN_URL = "url";
    public static final String COLUMN_RULE = "rule";

    /**
     * 构造方法
     * @param json
     */
    public ShareEntity(JSONObject json){
        this.fromJSON(json);
    }

    @Override
    public JSONObject toJSON() {
        JSONObject result = super.toJSON();
        try {
            result.put(COLUMN_ICON, this.icon);
            result.put(COLUMN_TITLE, this.title);
            result.put(COLUMN_DESCRIPTION, this.description);
            result.put(COLUMN_URL, this.url);
            result.put(COLUMN_RULE, this.rule);

        } catch (JSONException e) {
            e.printStackTrace();
        }

        return result;
    }

    @Override
    public void fromJSON(JSONObject json) {
        super.fromJSON(json);

        if(Helper.isNotEmpty(json)) {
            this.icon = json.optString(COLUMN_ICON);
            this.title = json.optString(COLUMN_TITLE);
            this.description = json.optString(COLUMN_DESCRIPTION);
            this.url = json.optString(COLUMN_URL);
            this.rule = json.optString(COLUMN_RULE);
        }
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getRule() {
        return rule;
    }

    public void setRule(String rule) {
        this.rule = rule;
    }
}
